import os
from dotenv import load_dotenv

# 加载.env文件
load_dotenv()

class Config:
    """配置类"""
    
    # 数据库配置
    host = os.getenv('DB_HOST', 'localhost')
    user = os.getenv('DB_USER', 'root')
    password = os.getenv('DB_PASSWORD', '')
    database = os.getenv('DB_NAME', 'brain_wave_db')
    port = int(os.getenv('DB_PORT', 3306))
    
    # 设备配置
    DEVICE_PORT = os.getenv('DEVICE_PORT', 'COM5')
    DEVICE_BAUDRATE = int(os.getenv('DEVICE_BAUDRATE', 57600))
    
    # 采样率配置
    SAMPLING_RATE = int(os.getenv('SAMPLING_RATE', 512))
    FRAME_RATE = int(os.getenv('FRAME_RATE', 512))
    FREQUENCY_FRAME_RATE = int(os.getenv('FREQUENCY_FRAME_RATE', 1))
    
    # 频段配置
    # Delta波：深度睡眠
    DELTA_RANGE = (0.5, 4.0)
    # Theta波：浅睡眠、冥想
    THETA_RANGE = (4.0, 8.0)
    # Alpha波：放松、清醒
    ALPHA_RANGE = (8.0, 12.0)
    # Beta波：专注、思考
    BETA_RANGE = (12.0, 30.0)
    # Gamma波：高度认知
    GAMMA_RANGE = (30.0, 50.0)
    # 过滤后的Delta波范围
    FILTERED_DELTA_RANGE = (2.0, 4.0)
    
    # 设备信息
    DEVICE_NAME = os.getenv('DEVICE_NAME', 'NeuroSky MindWave')
    DEVICE_TYPE = os.getenv('DEVICE_TYPE', 'EEG')
    DEVICE_SAMPLING_RATE = int(os.getenv('DEVICE_SAMPLING_RATE', 512))  # NeuroSky实际采样率是512Hz
    DEVICE_TRANSMISSION_RATE = int(os.getenv('DEVICE_TRANSMISSION_RATE', 512))
    
    # 日志配置
    LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
    LOG_FILE = os.getenv('LOG_FILE', 'logs/brain_wave.log')
    
    # 数据压缩配置
    COMPRESSION_ALGORITHM = os.getenv('COMPRESSION_ALGORITHM', 'zstd')
    COMPRESSION_LEVEL = int(os.getenv('COMPRESSION_LEVEL', 3))